﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class sysadmin_CountManager_ProjectDetail :PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Project.ProjectUser opProjectUser = new PowerCreator.LMS.Web.Project.ProjectUser();
    PowerCreator.LMS.ViewQuery.ViewQuery opViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();

    string _cmd1 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and FKSpplogTrainclaID={1}";   //查询总人数
    string _cmd2 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and FKSpplogTrainclaID={1} and SpplogState=16";  //通过人数
    string _cmd3 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and FKSpplogTrainclaID={1} and SpplogState=17";  //未通过人数

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            string projectid = Request.QueryString["ProjectID"].ToString();
            ViewState["ProjectID"] = projectid;

            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search, 1);
        }
    }
    protected override void InitPage()
    {
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = string.Format("FKTrainclaTrainproID={0}", ViewState["ProjectID"]);
        return search;
    }
    private void BinderPager(string search)
    {
        AspNetPager1.PageSize = LMSPageSize;
        AspNetPager1.RecordCount = opProjectUser.QueryProjectClassCount(search);
    }
    private void BinderRPT(string search,int pageIndex)
    {
        DataTable dt = opProjectUser.QueryProjectClass(search,LMSPageSize,pageIndex);

        dt.Columns.Add("ProjectStudentClassCount1");    //总人数
        dt.Columns.Add("ProjectStudentClassCountYes1"); //通过人数
        dt.Columns.Add("ProjectStudentClassCountNo1");  //未通过人数
        string cmd1, cmd2, cmd3;

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            cmd1 = string.Format(_cmd1, ViewState["ProjectID"], dt.Rows[i]["TrainclaID"]);
            cmd2 = string.Format(_cmd2, ViewState["ProjectID"], dt.Rows[i]["TrainclaID"]);
            cmd3 = string.Format(_cmd3, ViewState["ProjectID"], dt.Rows[i]["TrainclaID"]);

            dt.Rows[i]["ProjectStudentClassCount1"] = opViewQuery.Query(cmd1, 1, 1).Rows[0][0];
            dt.Rows[i]["ProjectStudentClassCountYes1"] = opViewQuery.Query(cmd2, 1, 1).Rows[0][0];
            dt.Rows[i]["ProjectStudentClassCountNo1"] = opViewQuery.Query(cmd3, 1, 1).Rows[0][0];
        }

        rpt_ProjectClass.DataSource = dt;
        rpt_ProjectClass.DataBind();
    }
    protected void rpt_ProjectClass_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "ldetail")
        {
            string url = "ProjectDetailClass.aspx?ClassID=" + e.CommandArgument.ToString();
            PowerCreator.LMS.Common.Script.Script.RedirectURL(url);
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
}
